package org.ns.framework.datasource.config;

import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;

import com.alibaba.druid.pool.DruidDataSource;

public class DruidDataSourceConfig extends DruidDataSource {

	private static final long serialVersionUID = 1L;


	public void setUseGlobalDataSourceStat(boolean arg) { super.setUseGlobalDataSourceStat(arg);}
	public void setResetStatEnable(boolean arg) { super.setResetStatEnable(arg);}
	public void setEnable(boolean arg) { super.setEnable(arg);}
	public void setPoolPreparedStatements(boolean arg) { super.setPoolPreparedStatements(arg);}
	public void setMaxActive(int arg) { super.setMaxActive(arg);}
	public void setLogDifferentThread(boolean arg) { super.setLogDifferentThread(arg);}
	public boolean isEnable(){ return super.isEnable(); }
	public boolean isUseGlobalDataSourceStat(){ return super.isUseGlobalDataSourceStat(); }
	public boolean isResetStatEnable(){ return super.isResetStatEnable(); }
	public boolean isLogDifferentThread(){ return super.isLogDifferentThread(); }
	public String getName(){ return super.getName(); }
	public void setName(String arg) { super.setName(arg);}
	public void setUrl(String arg) { super.setUrl(arg);}
	public String getUrl(){ return super.getUrl(); }
	public String getDbType(){ return super.getDbType(); }
	public int getInitialSize(){ return super.getInitialSize(); }
	public String getDriverClassName(){ return super.getDriverClassName(); }
	public String getValidationQuery(){ return super.getValidationQuery(); }
	public long getTimeBetweenEvictionRunsMillis(){ return super.getTimeBetweenEvictionRunsMillis(); }
	public int getMaxWaitThreadCount(){ return super.getMaxWaitThreadCount(); }
	public String getUsername(){ return super.getUsername(); }
	public int getMinIdle(){ return super.getMinIdle(); }
	public int getMaxActive(){ return super.getMaxActive(); }
	public int getQueryTimeout(){ return super.getQueryTimeout(); }
	public int getTransactionQueryTimeout(){ return super.getTransactionQueryTimeout(); }
	public int getLoginTimeout(){ return super.getLoginTimeout(); }
	public String getValidConnectionCheckerClassName(){ return super.getValidConnectionCheckerClassName(); }
	public String getExceptionSorterClassName(){ return super.getExceptionSorterClassName(); }
	public Integer getDefaultTransactionIsolation(){ return super.getDefaultTransactionIsolation(); }
	public String getPassword(){ return super.getPassword(); }
	public long getMinEvictableIdleTimeMillis(){ return super.getMinEvictableIdleTimeMillis(); }
	public int getValidationQueryTimeout(){ return super.getValidationQueryTimeout(); }
	public long getRemoveAbandonedTimeoutMillis(){ return super.getRemoveAbandonedTimeoutMillis(); }
	public long getTimeBetweenLogStatsMillis(){ return super.getTimeBetweenLogStatsMillis(); }
	public long getMaxWait(){ return super.getMaxWait(); }
	public String getDefaultCatalog(){ return super.getDefaultCatalog(); }
	public int getMaxIdle(){ return super.getMaxIdle(); }
	public long getTimeBetweenConnectErrorMillis(){ return super.getTimeBetweenConnectErrorMillis(); }
	public int getMaxOpenPreparedStatements(){ return super.getMaxOpenPreparedStatements(); }
	public int getConnectionErrorRetryAttempts(){ return super.getConnectionErrorRetryAttempts(); }
	public int getMaxPoolPreparedStatementPerConnectionSize(){ return super.getMaxPoolPreparedStatementPerConnectionSize(); }
	public long getTransactionThresholdMillis(){ return super.getTransactionThresholdMillis(); }
	public int getRemoveAbandonedTimeout(){ return super.getRemoveAbandonedTimeout(); }
	public long getMaxEvictableIdleTimeMillis(){ return super.getMaxEvictableIdleTimeMillis(); }
	public long getPhyTimeoutMillis(){ return super.getPhyTimeoutMillis(); }
	public int getNumTestsPerEvictionRun(){ return super.getNumTestsPerEvictionRun(); }
	public int getNotFullTimeoutRetryCount(){ return super.getNotFullTimeoutRetryCount(); }
	public int getMaxCreateTaskCount(){ return super.getMaxCreateTaskCount(); }
	public void setUseLocalSessionState(boolean arg) { super.setUseLocalSessionState(arg);}
	public void setOracle(boolean arg) { super.setOracle(arg);}
	public void setUseUnfairLock(boolean arg) { super.setUseUnfairLock(arg);}
	public void setDupCloseLogEnable(boolean arg) { super.setDupCloseLogEnable(arg);}
	public void setBreakAfterAcquireFailure(boolean arg) { super.setBreakAfterAcquireFailure(arg);}
	public void setConnectionErrorRetryAttempts(int arg) { super.setConnectionErrorRetryAttempts(arg);}
	public void setSharePreparedStatements(boolean arg) { super.setSharePreparedStatements(arg);}
	public void setTimeBetweenConnectErrorMillis(long arg) { super.setTimeBetweenConnectErrorMillis(arg);}
	public void setMaxOpenPreparedStatements(int arg) { super.setMaxOpenPreparedStatements(arg);}
	public void setRemoveAbandonedTimeout(int arg) { super.setRemoveAbandonedTimeout(arg);}
	public void setRemoveAbandonedTimeoutMillis(long arg) { super.setRemoveAbandonedTimeoutMillis(arg);}
	public void setRemoveAbandoned(boolean arg) { super.setRemoveAbandoned(arg);}
	public void setNumTestsPerEvictionRun(int arg) { super.setNumTestsPerEvictionRun(arg);}
	public void setTimeBetweenEvictionRunsMillis(long arg) { super.setTimeBetweenEvictionRunsMillis(arg);}
	public void setValidationQueryTimeout(int arg) { super.setValidationQueryTimeout(arg);}
	public void setAccessToUnderlyingConnectionAllowed(boolean arg) { super.setAccessToUnderlyingConnectionAllowed(arg);}
	public void setDefaultCatalog(String arg) { super.setDefaultCatalog(arg);}
	public void setMaxWait(long arg) { super.setMaxWait(arg);}
	public void setMaxIdle(int arg) { super.setMaxIdle(arg);}
	public void setUsername(String arg) { super.setUsername(arg);}
	public void setPassword(String arg) { super.setPassword(arg);}
	public void setAsyncCloseConnectionEnable(boolean arg) { super.setAsyncCloseConnectionEnable(arg);}
	public void setMaxCreateTaskCount(int arg) { super.setMaxCreateTaskCount(arg);}
	public void setStatLoggerClassName(String arg) { super.setStatLoggerClassName(arg);}
	public void setConnectionProperties(String arg) { super.setConnectionProperties(arg);}
	public void setLogAbandoned(boolean arg) { super.setLogAbandoned(arg);}
	public void setMaxPoolPreparedStatementPerConnectionSize(int arg) { super.setMaxPoolPreparedStatementPerConnectionSize(arg);}
	public void setTransactionThresholdMillis(long arg) { super.setTransactionThresholdMillis(arg);}
	public void setUseOracleImplicitCache(boolean arg) { super.setUseOracleImplicitCache(arg);}
	public void setTestWhileIdle(boolean arg) { super.setTestWhileIdle(arg);}
	public void setTestOnBorrow(boolean arg) { super.setTestOnBorrow(arg);}
	public void setValidationQuery(String arg) { super.setValidationQuery(arg);}
	public void setTimeBetweenLogStatsMillis(long arg) { super.setTimeBetweenLogStatsMillis(arg);}
	public void setClearFiltersEnable(boolean arg) { super.setClearFiltersEnable(arg);}
	public void setNotFullTimeoutRetryCount(int arg) { super.setNotFullTimeoutRetryCount(arg);}
	public void setMaxWaitThreadCount(int arg) { super.setMaxWaitThreadCount(arg);}
	public void setFailFast(boolean arg) { super.setFailFast(arg);}
	public void setPhyTimeoutMillis(long arg) { super.setPhyTimeoutMillis(arg);}
	public void setMinEvictableIdleTimeMillis(long arg) { super.setMinEvictableIdleTimeMillis(arg);}
	public void setMaxEvictableIdleTimeMillis(long arg) { super.setMaxEvictableIdleTimeMillis(arg);}
	public void setDbType(String arg) { super.setDbType(arg);}
	public void setDriverClassName(String arg) { super.setDriverClassName(arg);}
	public void setInitialSize(int arg) { super.setInitialSize(arg);}
	public void setMinIdle(int arg) { super.setMinIdle(arg);}
	public void setQueryTimeout(int arg) { super.setQueryTimeout(arg);}
	public void setTransactionQueryTimeout(int arg) { super.setTransactionQueryTimeout(arg);}
	public void setLoginTimeout(int arg) { super.setLoginTimeout(arg);}
	public void setTestOnReturn(boolean arg) { super.setTestOnReturn(arg);}
	public void setDefaultAutoCommit(boolean arg) { super.setDefaultAutoCommit(arg);}
	public void setDefaultTransactionIsolation(Integer arg) { super.setDefaultTransactionIsolation(arg);}
	public boolean isUseLocalSessionState(){ return super.isUseLocalSessionState(); }
	public boolean isUseUnfairLock(){ return super.isUseUnfairLock(); }
	public boolean isDupCloseLogEnable(){ return super.isDupCloseLogEnable(); }
	public boolean isAccessToUnderlyingConnectionAllowed(){ return super.isAccessToUnderlyingConnectionAllowed(); }
	public boolean isClearFiltersEnable(){ return super.isClearFiltersEnable(); }
	public boolean isFailFast(){ return super.isFailFast(); }
	public boolean isTestOnBorrow(){ return super.isTestOnBorrow(); }
	public boolean isTestOnReturn(){ return super.isTestOnReturn(); }
	public boolean isTestWhileIdle(){ return super.isTestWhileIdle(); }
	public boolean isOracle(){ return super.isOracle(); }
	public boolean isUseOracleImplicitCache(){ return super.isUseOracleImplicitCache(); }
	public boolean isRemoveAbandoned(){ return super.isRemoveAbandoned(); }
	public boolean isDefaultAutoCommit(){ return super.isDefaultAutoCommit(); }
	public boolean isAsyncCloseConnectionEnable(){ return super.isAsyncCloseConnectionEnable(); }
	public boolean isLogAbandoned(){ return super.isLogAbandoned(); }
	public boolean isPoolPreparedStatements(){ return super.isPoolPreparedStatements(); }
	public boolean isSharePreparedStatements(){ return super.isSharePreparedStatements(); }
	public boolean isBreakAfterAcquireFailure(){ return super.isBreakAfterAcquireFailure(); }

			

	public static void main(String[] args) {
		Class<?> type = DruidDataSource.class;
		Set<String> ff = new HashSet<>();
		while(type != Object.class) {
			Method[] methods = type.getMethods();
			for (Method method : methods) {
				String name = method.getName();
				if (!ff.add(name) || method.getExceptionTypes().length > 0) {
					continue;
				}
				
				StringBuilder builder = new StringBuilder();
				Class<?> ptypes[] = method.getParameterTypes();
				Class<?> rtypes = method.getReturnType();
				
				if (name.startsWith("set") && ptypes.length == 1) {
					if (canType(ptypes[0])) {
						builder.append("public void ").append(name).append("(");
						builder.append(ptypes[0].getSimpleName()).append(" arg)");
						builder.append(" { super.").append(name).append("(arg);}");
					}
				} 
				else if (name.startsWith("get") && ptypes.length == 0 && rtypes != void.class && existSet(method, type)) {
					if (canType(rtypes)) {
						builder.append("public ").append(rtypes.getSimpleName()).append(" ").append(name).append("()");
						builder.append("{ return super.").append(name).append("(); }");
					}
				} else if (name.startsWith("is") && ptypes.length == 0 && rtypes == boolean.class && existSet(method, type)) {
					if (canType(rtypes)) {
						builder.append("public ").append(rtypes.getSimpleName()).append(" ").append(name).append("()");
						builder.append("{ return super.").append(name).append("(); }");
					}
				}
				if (builder.length() > 0) {
					System.out.println(builder);
				}
			}
			type = type.getSuperclass();
		}
	}
	
	private static boolean existSet(Method getMethod, Class<?> type) {
		String name = getMethod.getName();
		try {
			if (name.startsWith("get")) {
				type.getMethod("set" + name.substring(3), getMethod.getReturnType());
			} else if (name.startsWith("is")) {
				type.getMethod("set" + name.substring(2), getMethod.getReturnType());
			}
			return true;
		} catch (Exception e) {
			return false;
		}
	}
	
	private static boolean canType(Class<?> type) {
		if (type.isPrimitive()) {
			return true;
		}
		if (Number.class.isAssignableFrom(type)) {
			return true;
		}
		if (type == String.class) {
			return true;
		}
		return false;
	}
}
